package com.superman.supermarket.client.composite.orderlist.opt;

import java.util.Map;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.superman.supermarket.client.constant.OrderListOperationConstants;
import com.superman.supermarket.client.gin.ShopGinjector;

/**
 * 订单列表中的操作按钮
 * 
 * @author superman
 * @version 2017年4月13日下午1:58:37
 */
public class OrderListOpButton extends Button {

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2017年4月13日 下午2:16:58
	 * @param map
	 * @param op
	 */
	public OrderListOpButton(final Map<String, Object> map, final int op) {
		this.setSize("1.866667rem ", "0.666667rem");
		this.getElement().getStyle().setProperty("fontSize", "14px");
		this.getElement().getStyle().setProperty("borderRadius", "0.106667rem");
		this.getElement().getStyle().setProperty("border", "1px solid #ccc");
		this.getElement().getStyle().setProperty("background", "#fff");
		this.getElement().getStyle().setProperty("color", "#333");
		setButtonName(op);

		this.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				event.stopPropagation();
				ShopGinjector.INSTANCE.getOpButtonOperatorFactory().option(map, op);
			}
		});
	}

	/**
	 * 根据后台的按钮编号来展示对应按钮
	 * 
	 * @author superman
	 * @version 2017年4月13日 下午2:16:38
	 * @param op
	 */
	private void setButtonName(int op) {
		switch (op) {
			case OrderListOperationConstants.Pay:
				this.setText("付款");
				setPayStyle();
				break;
			case OrderListOperationConstants.Cancel:
				this.setText("取消订单");
				break;
			case OrderListOperationConstants.Confirm:
				this.setText("确认收货");
				setPayStyle();
				break;
			case OrderListOperationConstants.Comment:
				this.setText("评价");
				setPayStyle();
				break;
			case OrderListOperationConstants.LogisticsState:
				this.setText("查看物流");
				break;
			/** 以下按钮是订单详情中才会出现的 **/
			case OrderListOperationConstants.Refund:
				this.setText("退款");
				break;
			case OrderListOperationConstants.AfterSales:
				this.setText("申请售后");
				break;
			case OrderListOperationConstants.Refunding:
				this.setText("退款中");
				break;
			case OrderListOperationConstants.ReturnGoods:
				this.setText("退货");
				break;
			case OrderListOperationConstants.CloseRefundApplication:
				this.setText("撤销申请");
				break;
			case OrderListOperationConstants.UpdateRefundApplication:
				this.setText("修改申请");
				break;
			case OrderListOperationConstants.RefundSuccess:
				this.setText("退款成功");
				break;
			case OrderListOperationConstants.RefundRefused:
				this.setText("退款失败");
				break;
			/** 以上按钮是订单详情中才会出现的 **/
			case OrderListOperationConstants.TicketList:
				this.setText("查看票码");
				break;
			case OrderListOperationConstants.DeleteOrder:
				this.setText("删除订单");
				break;
		}
	}

	/**
	 * 设置付款按钮样式，确认收货，评价
	 * 
	 * @author superman
	 * @version 2017年4月13日 下午2:08:15
	 */
	private void setPayStyle() {
		this.getElement().getStyle().setProperty("background", "#e31436");
		this.getElement().getStyle().setProperty("color", "#fff");
		this.getElement().getStyle().setProperty("border", "1px solid #e31436");
	}
}
